<!DOCTYPE html>
<html lang="en">
<head>
    <title>AGV导航演示</title>
	<meta charset="utf-8">
	<meta http-equiv="content-type" content="text/html;utf-8" />
	<meta name="keywords" content="agv" />
	<meta name="description" content="AGV" />
	<meta name="author" content="ttscm.com.cn" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no" />
	<script src="js/jquery-3.6.0.min.js"></script>

	<script>
		var iStatusCode = -1;
		var statusInterval = null;
		
		$(function() {
			
			//
			$.getJSON("nav/listSite", function(result) {
				if (result.code != 0) {
					console.debug(result);
					return;
				}
				
				let blankOption = "<option value=''>---请选择目标站点---</option>";
				$("#selTargetSite").append(blankOption);
				for (let i=0; i<result.data.length; i++) {
					let strOption = "<option value='" + result.data[i].value + "'>" + result.data[i].text + "</option>";
					$("#selTargetSite").append(strOption);
				}
			});
			
			//
			$("#btnExecute").click(function() {
				iStatusCode = 2;
				let targetSite = $("#selTargetSite").val();
				if (targetSite == "") {
					$("#areaExecuteStatus").css("color", "#FF0000");
					$("#areaExecuteStatus").text("请选择目的站点...");
					return;
				}
				$("#areaExecuteStatus").css("color", "#000000");
				$("#areaExecuteStatus").text("正在下发调度指令...");
				let strUrl = "nav/execTask/" + targetSite;
				$.getJSON(strUrl, function(result) {
					if (result.code != 0) {
						$("#areaExecuteStatus").css("color", "#FF0000");
						$("#areaExecuteStatus").text("异常代码：" + result.code + "\n\n异常消息：" + result.message);
						return;
					}
					$("#areaExecuteStatus").css("color", "#000000");
					$("#areaExecuteStatus").text("调度指令下发正常...");
				});
				statusInterval = setInterval(queryStatus, 1000);
			});

			//智飞龙科马
			$("#btnZflkm").click(function() {
				iStatusCode = 2;
				$("#areaExecuteStatus").css("color", "#000000");
				$("#areaExecuteStatus").text("正在下发调度指令...");
				let strUrl = "nav/zflkm2/";
				$.getJSON(strUrl, function(result) {
					if (result.code != 0) {
						$("#areaExecuteStatus").css("color", "#FF0000");
						$("#areaExecuteStatus").text("异常代码：" + result.code + "\n\n异常消息：" + result.message);
						return;
					}
					$("#areaExecuteStatus").css("color", "#000000");
					$("#areaExecuteStatus").text("调度指令下发正常...");
				});
				statusInterval = setInterval(queryStatus, 1000);
			});
			
			$("#btnZflkmSend").click(function() {
				$("#areaExecuteStatus").css("color", "#000000");
				$("#areaExecuteStatus").text("正在发送信号...");
				let strUrl = "nav/sendSignal/";
				$.getJSON(strUrl, function(result) {
					if (result.code != 0) {
						$("#areaExecuteStatus").css("color", "#FF0000");
						$("#areaExecuteStatus").text("异常代码：" + result.code + "\n\n异常消息：" + result.message);
						return;
					}
					$("#areaExecuteStatus").css("color", "#000000");
					$("#areaExecuteStatus").text("信号发送正常...");
				});
			});

			$("#btnZflkmRead").click(function() {
				$("#areaExecuteStatus").css("color", "#000000");
				$("#areaExecuteStatus").text("正在读取信号...");
				let strUrl = "nav/readSignal/";
				$.getJSON(strUrl, function(result) {
					if (result.code != 0) {
						$("#areaExecuteStatus").css("color", "#FF0000");
						$("#areaExecuteStatus").text("异常代码：" + result.code + "\n\n异常消息：" + result.message);
						return;
					}
					$("#areaExecuteStatus").css("color", "#000000");
					$("#areaExecuteStatus").text("读取值："  + result.data);
				});
			});
			
		});
		
		// 状态查询
		function queryStatus() {
			console.debug("---queryStatus---");
			$.getJSON("nav/location", function(result) {
				//console.info(result);
				if (result.code != 0) {
					console.debug(result);
					return;
				}
				$("#txtCurrSite").val(result.data);
			});

			$.getJSON("nav/taskStatus", function(result) {
				if (result.code != 0) {
					console.info(result);
					iStatusCode = -1;
					console.debug(result);
					return;
				}
				iStatusCode = result.data.statusCode;
				//console.info(result.data.statusCode);
				$("#areaExecuteStatus").val(result.data.statusDesc);
			});
			
			if (iStatusCode != 2) {
				clearInterval(statusInterval);
			}
			if (iStatusCode == 4) {
				// 呼叫线边设备
				// 查询线边设备完成状态（呼叫机器人拉回空蛋车车）
			}
		}


  </script>
</head>
<body style="font-size:100%;">
	<div id="container" style="border:0px solid #FF0000;margin:0px;padding:1px;">
		<div id="header" style="border:0px solid #00FF00;background-color:#C0C0C0;text-align:center;font-size:200%;margin:5px;padding:1px;">
			<b>导航演示</b>
		</div>

		<div id="content" style="border:0px solid #0000FF;background-color:#EEEEEE;margin:5px;padding:1px;">	
			<table style="width:100%;">
				<tr>
					<td style="width:30%;"><label for="txtCurrSite">当前站点：</label></td>
					<td style="width:70%;"><input id="txtCurrSite" type="text" style="width:95%;height:25px;" disabled="disabled" /></td>
				</tr>
				<tr>
					<td ><label for="selTargetSite">目标站点：</label></td>
					<td ><select id="selTargetSite" style="width:95%;height:30px;"></select></td>
				</tr>
				<tr>
					<td colspan="2" style="text-align:center;height:80px;">
						<button id="btnExecute" type="button" style="width:100%;height:50px;background-color:red;">执行</button>
						<button id="btnZflkm" type="button" style="width:100%;height:50px;background-color:red;">取料-上料</button>
						
						<button id="btnZflkmSend" type="button" style="width:100%;height:50px;background-color:red;">发送信号</button>
						<button id="btnZflkmRead" type="button" style="width:100%;height:50px;background-color:red;">读取信号</button>
					</td>
				</tr>
				<tr>
					<td>
						<label for="areaExecuteStatus" >执行状态：</label>
					</td>
					<td style="text-align:center;">
						<textarea id="areaExecuteStatus" style="width:95%;min-height:400px;font-size:150;font-weight:bold;color:#000000%" disabled="disabled"></textarea>
					</td>
				</tr>
			</table>
		</div>

		<div id="footer" style="border:0px solid #00FF00;background-color:#C0C0C0;text-align:center;margin:5px;padding:1px;">
			版权 &#169 天天供应链 &#8226 天天智能科技
		</div>
	</div>
</body>
</html>